package com.sanrenzu.chunbo.ui.foodagency;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.sanrenzu.chunbo.R;
import com.sanrenzu.chunbo.bean.gy.NewFoodTypeBean;

import java.util.List;

/**
 * Created by Administrator on 2016/8/31 0031.
 */
public class NewFoodAdapter extends BaseAdapter{
    private Context mContext;
    private List<NewFoodTypeBean> list;
    private LayoutInflater inflater;

    public NewFoodAdapter(Context mContext,List<NewFoodTypeBean> list){
        this.mContext=mContext;
        this.list=list;
        inflater= (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }
    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        MyViewHolder myViewHolder=null;
        if(convertView==null){
            convertView=inflater.inflate(R.layout.listview_newfood_foodagency,parent,false);
            myViewHolder=new MyViewHolder(convertView);
            convertView.setTag(myViewHolder);
        }else {
            myViewHolder= (MyViewHolder) convertView.getTag();
        }
        myViewHolder.textView_displayName_newFood.setText(list.get(position).getDisplayName());
        myViewHolder.textView_desc_newFood.setText(list.get(position).getDesc());
        myViewHolder.textView_chefName_newFood.setText(list.get(position).getChefName());
        Glide.with(mContext).load(list.get(position).getPicUrl()).into(myViewHolder.imageView_newFood_agency);
        return convertView;
    }
    class MyViewHolder{
        private ImageView imageView_newFood_agency;
        private TextView textView_displayName_newFood;
        private TextView textView_desc_newFood;
        private TextView textView_chefName_newFood;
        public MyViewHolder(View convertView){
            imageView_newFood_agency=
                    (ImageView) convertView.findViewById(R.id.imageView_newFood_agency);
            textView_displayName_newFood=
                    (TextView) convertView.findViewById(R.id.textView_displayName_newFood);
            textView_desc_newFood=
                    (TextView) convertView.findViewById(R.id.textView_desc_newFood);
            textView_chefName_newFood=
                    (TextView) convertView.findViewById(R.id.textView_chefName_newFood);
        }
    }
}
